Skip to content

fix: prevent premature context cancellation in writeRaw (WriteRawWithContext/PatchRawWithContext) [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #32066

Open
waterWang wants to merge 1 commit into
hashicorp:mainfrom
waterWang:fix/write-raw-context-cancel
Open

fix: prevent premature context cancellation in writeRaw (WriteRawWithContext/PatchRawWithContext) [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT]#32066
waterWang wants to merge 1 commit into
hashicorp:mainfrom
waterWang:fix/write-raw-context-cancel

Conversation

@waterWang

Copy link
Copy Markdown

Description

WriteRawWithContext and PatchRawWithContext return a *Response whose body is bound to an already-cancelled context. Reading the body then fails with a spurious context canceled, even though the request succeeded server-side.

Root Cause

Both methods route through writeRaw, which wraps the context with a timeout via withConfiguredTimeout and then defer cancelFunc() — the cancel fires before the caller can read resp.Body.

The read path (readRawWithDataWithContext) and delete path (DeleteRawWithContext) already fixed this (#18708) by routing through Client.RawRequestWithContext, which wraps the context with a timeout but discards the cancel function — the comment explains: "when canceled, the request.Body will EOF when reading due to the way it streams data in."

Fix

Route writeRaw through Client.RawRequestWithContext instead of manually wrapping the context with withConfiguredTimeout + defer cancelFunc(). This matches the pattern used by readRawWithDataWithContext, DeleteRawWithContext, and all other raw methods.

Testing

  • WriteRawWithContext / PatchRawWithContext now return a body that remains readable after the function returns
  • The client-configured timeout is still enforced by RawRequestWithContext's internal withConfiguredTimeout call
  • Small responses continue to work as before
  • Large responses no longer fail with context canceled

Fixes #31986

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jul 31, 2026
@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

Deployment failed with the following error:

The `vercel.json` schema validation failed with the following message: should NOT have additional property `public`

Learn More: https://vercel.com/docs/concepts/projects/project-configuration

@dosubot dosubot Bot added bug Used to indicate a potential bug core/client labels Jul 31, 2026
@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vault-ui Error Error Jul 31, 2026 3:47pm

Request Review

@hashicorp-cla-app

Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

1 similar comment
@hashicorp-cla-app

Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Used to indicate a potential bug core/client size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

api: Logical.writeRaw cancels the response body's context before the caller reads it (same defect as #18658, write/patch path)

1 participant